package com.cyl.manager.del.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.cyl.manager.del.convert.LbsMgzConvert;
import com.cyl.manager.del.domain.LbsMgz;
import com.cyl.manager.del.pojo.query.LbsMgzQuery;
import com.cyl.manager.del.service.LbsMgzService;
import com.cyl.manager.del.pojo.vo.LbsMgzVO;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
/**
 * 敏感字管理Controller
 *
 * @author zcc
 * @date 2025-02-21
 */
@Api(description ="敏感字管理接口列表")
@RestController
@RequestMapping("/del/lbsMgz")
public class LbsMgzController extends BaseController {
    @Autowired
    private LbsMgzService service;
    @Autowired
    private LbsMgzConvert convert;

    @ApiOperation("查询敏感字管理列表")
    @PreAuthorize("@ss.hasPermi('del:lbsMgz:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<LbsMgz>> list(@RequestBody LbsMgzQuery query, Pageable page) {
    	Long qrDeptZbjId = SecurityUtils.getDeptZbjId();
        if(qrDeptZbjId!=null) {
        	query.setDeptZbjId(qrDeptZbjId);
        }
        List<LbsMgz> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @ApiOperation("导出敏感字管理列表")
    @PreAuthorize("@ss.hasPermi('del:lbsMgz:export')")
    @Log(title = "敏感字管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(LbsMgzQuery query) {
    	Long qrDeptZbjId = SecurityUtils.getDeptZbjId();
        if(qrDeptZbjId!=null) {
        	query.setDeptZbjId(qrDeptZbjId);
        }
        List<LbsMgz> list = service.selectList(query, null);
        ExcelUtil<LbsMgzVO> util = new ExcelUtil<>(LbsMgzVO.class);
        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "敏感字管理数据"));
    }

    @ApiOperation("获取敏感字管理详细信息")
    @PreAuthorize("@ss.hasPermi('del:lbsMgz:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<LbsMgz> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.selectById(id));
    }
    
    @ApiOperation("获取敏感字管理详细信息")
    @PreAuthorize("@ss.hasPermi('del:lbsMgz:query')")
    @GetMapping(value = "/getMgsString")
    public ResponseEntity<LbsMgz> getMgsString() {
    	Long qrDeptZbjId = SecurityUtils.getDeptZbjId();
    	LbsMgz lbsMgz =new LbsMgz();
    	lbsMgz.setMgz(service.getMgsString(qrDeptZbjId));
        return ResponseEntity.ok(lbsMgz);
    }
    
    
    @ApiOperation("新增敏感字管理")
    @PreAuthorize("@ss.hasPermi('del:lbsMgz:add')")
    @Log(title = "敏感字管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody LbsMgz lbsMgz) {
    	 Long qrDeptZbjId = SecurityUtils.getDeptZbjId();
         if(qrDeptZbjId!=null) {
        	 lbsMgz.setDeptZbjId(qrDeptZbjId);
         }
        return ResponseEntity.ok(service.insert(lbsMgz));
    }

    @ApiOperation("修改敏感字管理")
    @PreAuthorize("@ss.hasPermi('del:lbsMgz:edit')")
    @Log(title = "敏感字管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody LbsMgz lbsMgz) {
    	 Long qrDeptZbjId = SecurityUtils.getDeptZbjId();
         if(qrDeptZbjId!=null) {
        	 lbsMgz.setDeptZbjId(qrDeptZbjId);
         }
        return ResponseEntity.ok(service.update(lbsMgz));
    }

    @ApiOperation("删除敏感字管理")
    @PreAuthorize("@ss.hasPermi('del:lbsMgz:remove')")
    @Log(title = "敏感字管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }
}
